package com.ciaojian.client.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Atlakyn
 */
@Configuration
@EnableSwagger2
public class SwaggerDocConfig {

    @Bean
    public Docket getDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户端")
                .apiInfo(apiInfo("其他接口", "1.0.0", "其他接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ciaojian.client.controller"))
                .build();
    }

    @Bean
    public Docket restOrderApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("订单接口")
                .apiInfo(apiInfo("订单接口", "1.0.0", "订单相关接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ciaojian.client.controller"))
                .paths(PathSelectors.regex("/order.*"))
                .build();
    }

    private ApiInfo apiInfo(String title, String version, String description) {
        return new ApiInfoBuilder()
                .contact(new Contact("Atlakyn", "", ""))
                .title(title)
                .description(description)
                .version(version)
                .build();
    }

}
